package Work;

import java.util.Vector;

public class OutputWordMess {

    public static void main(String[] args) {
        Vector<String> allWord,noSameWord;
        WordStatics statics =new WordStatics();
        statics.setFileName("src/chapter10/实验1输入输出流/english.txt");
        statics.wordStatic();
        allWord = statics.getAllWord();
        noSameWord = statics.getNoSameWord();
        System.out.println("共有"+allWord.size()+"个英文单词");
        System.out.println("有"+noSameWord.size()+"个互不相同的英文单词");
        System.out.println("按出现频率排列：");
        int count[] = new int[noSameWord.size()];
        for (int i = 0; i <noSameWord.size(); i++) {
            String s1 = noSameWord.elementAt(i);
            for (int j = 0; j < allWord.size(); j++) {
                String s2 = allWord.elementAt(j);
                if(s1.equals(s2))
                    count[i]++;

            }

        }

        for (int i = 0; i<noSameWord.size(); i++) {
            for (int j = i+1; j<noSameWord.size(); j++) {
                if(count[j]<count[i]) {
                    String temp = noSameWord.elementAt(i);
                    noSameWord.setElementAt(noSameWord.elementAt(j), i);
                    noSameWord.setElementAt(temp, j);
                    int t = count[i];
                    count[i] =count[j];
                    count[j]=t;
                }

            }

        }

        for (int i = 0; i <noSameWord.size(); i++) {
            double frequency =(1.0*count[i])/allWord.size();
            System.out.printf("%s:%-7.3f",noSameWord.elementAt(i),frequency);

        }
    }

}
